package com.kakaxi.mybilibili.adapter;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.kakaxi.mybilibili.R;
import com.kakaxi.mybilibili.bean.LiveAreaCategoryItemBean;

import java.util.List;

/**
 * 直播全部分类适配器
 * Created by kakaxi on 16/11/14.
 */

public class LiveAllCategoryRecyAdapter extends BaseQuickAdapter<LiveAreaCategoryItemBean,
        BaseViewHolder> {


    public LiveAllCategoryRecyAdapter(List<LiveAreaCategoryItemBean> data) {
        super(R.layout.item_recy_categroy_home_content, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, LiveAreaCategoryItemBean itemBean) {
        final TextView tv = baseViewHolder.getView(R.id.txt_category_content);
        tv.setText(itemBean.getName());
        // 获取图片并设置进文本控件中
        Glide.with(mContext).load(itemBean.getEntranceIcon().getSrc()).asBitmap().
                into(new SimpleTarget<Bitmap>() {

                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap>
                            glideAnimation) {
                        BitmapDrawable bitmapDrawable = new BitmapDrawable(mContext.getResources(),
                                resource);
                        bitmapDrawable.setBounds(0, 0, bitmapDrawable.getIntrinsicWidth(),
                                bitmapDrawable.getIntrinsicHeight());
                        tv.setCompoundDrawables(null, bitmapDrawable, null, null);
                    }
                });

    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(recyclerView.getContext()
                , 3);
        recyclerView.setLayoutManager(gridLayoutManager);
    }
}
